package com.moxigua.iotbox.util;

import java.util.Random;

/**
 * Created by Junerver on 2017/6/5.
 * Feature:
 * Updated:
 */

public class RandomUtil {
    public static int[] genSeeds(int min, int max) {
        int[] ret = new int[max - min + 1];
        int j = 0;
        for (int i = min; i <= max; i++) {
            ret[j++] = i;
        }
        return ret;
    }

    public static void main(String[] args) {
        // 种子随意生成，但不能重复
        int min = 20000000, max = 30000000;
        int[] seed = genSeeds(min, max);
        int[] ranArr = new int[max - min + 1];
        Random ran = new Random();

        for (int i = 0; i < seed.length; i++) {
            // 得到一个位置
            int j = ran.nextInt(seed.length - i);
            // 得到那个位置的数值
            ranArr[i] = seed[j];
            // 将最后一个未用的数字放到这里
            seed[j] = seed[seed.length - 1 - i];
        }


        //打印

        //System.out.println(“ranArr:” + Arrays.toString(ranArr));
        /*打印

        for (int i = 0; i < ranArr.length; i++) {
            System.out.print(ranArr[i] + “,”);
            if ((i % 500) == 0)
                System.out.println(“”);
        }*/
    }
}
